package com.bestcem.xm.award.controller;

import com.alibaba.fastjson.JSON;
import com.bestcem.xm.award.config.SignConfig;
import com.bestcem.xm.award.controller.convert.DrawAwardConvert;
import com.bestcem.xm.award.controller.convert.WinDataConvert;
import com.bestcem.xm.award.controller.param.draw.*;
import com.bestcem.xm.award.controller.vo.award.CreateAwardVO;
import com.bestcem.xm.award.controller.vo.draw.*;
import com.bestcem.xm.award.enums.AwardIssueStatusEnum;
import com.bestcem.xm.award.enums.AwardLevelEnum;
import com.bestcem.xm.award.grpc.service.param.draw.*;
import com.bestcem.xm.award.service.AwardDrawDisplayService;
import com.bestcem.xm.award.service.bo.award.AwardAwardBO;
import com.bestcem.xm.award.service.bo.award.WinDataBO;
import com.bestcem.xm.award.service.dto.FileInfoDTO;
import com.bestcem.xm.award.service.dto.awardaward.CreateAwardDTO;
import com.bestcem.xm.award.service.dto.draw.DrawAwardResultDTO;
import com.bestcem.xm.award.service.dto.draw.GetAwardDetailDTO;
import com.bestcem.xm.award.service.dto.draw.RecordDTO;
import com.bestcem.xm.award.service.dto.draw.RecordDetailDTO;
import com.bestcem.xm.award.service.impl.AwardDispatcher;
import com.bestcem.xm.common.core.constant.ReqErrorCodeConstants;
import com.bestcem.xm.common.core.domain.web.PageResultDTO;
import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.common.core.domain.web.XmResultJson;
import com.bestcem.xm.common.core.uitls.GRpcUtil;
import com.bestcem.xm.common.core.uitls.JsonUtil;
import com.bestcem.xm.common.core.uitls.SignUtil;
import com.bestcem.xm.component.security.context.SecurityContextHolder;
import com.fasterxml.jackson.core.type.TypeReference;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * 抽奖业务接口
 *
 * @author hang.li <hang.li@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/17 14:17
 */
@RestController
@RequestMapping(value = "/award/v3", produces = MediaType.APPLICATION_JSON_VALUE)
public class DrawAwardController {

    @Resource(name = "DrawNewAwardServiceImpl")
    private AwardDrawDisplayService awardDrawDisplayService;

    @Resource(name = "AwardDispatcher")
    private AwardDispatcher awardDispatcher;

    /**
     * 签名配置
     */
    @Resource
    protected SignConfig signConfig;

    /**
     * 发送短信验证码
     *
     * @param sendSmsVerificationCodeParam award_id deliver_id sig phone
     * @return ""
     */
    @ApiOperation(value = "发送短信验证码")
    @PostMapping(value = "draw/sms")
    public XmResultJson<Object> sendSmsVerificationCode(@RequestBody SendSmsVerificationCodeParam sendSmsVerificationCodeParam) {
        // 校验 sendSmsVerificationCodeParam 是否为null
        if (Objects.isNull(sendSmsVerificationCodeParam)) {
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_LOST, "入参缺失");
        }

        // 校验 award 是否为null
        if (Objects.isNull(sendSmsVerificationCodeParam.getAward())) {
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_LOST, "award不能为空");
        }

        // 验签
        String drawAwardKey = signConfig.getAwardKey();
        boolean respondentSign = SignUtil.checkSign(sendSmsVerificationCodeParam.getAward(), drawAwardKey);
        if (!respondentSign) {
            return XmResultJson.fail(ReqErrorCodeConstants.SIGN_ERROR, "invalid signature");
        }

        // 参数转换
        GetSmsCodeParam getSmsCodeParam = JSON.parseObject(JSON.toJSONString(sendSmsVerificationCodeParam.getAward()), GetSmsCodeParam.class);
        getSmsCodeParam.setPhone(sendSmsVerificationCodeParam.getPhone());

        // 校验 sendSmsVerificationCodeParam 参数
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(getSmsCodeParam);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }

        ServiceResult result = awardDrawDisplayService.getSmsAuthCode(getSmsCodeParam);
        if (result.isSuccess()) {
            return XmResultJson.success(result.getData());
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 短信验证码校验
     *
     * @param verifySmsVerificationCodeParam phone 抽奖手机号，code 验证码，award_id 奖励id，deliver_id 投放id
     *                                       ，award_page 页面唯一标识，survey_id 答卷id，sig
     * @return 校验结果
     */
    @ApiOperation(value = "短信验证码校验")
    @PostMapping(value = "draw/sms/auth")
    public XmResultJson<Object> verifySmsVerificationCode(@RequestBody VerifySmsVerificationCodeParam verifySmsVerificationCodeParam) {
        // 校验 verifySmsVerificationCodeParam 是否为null
        if (Objects.isNull(verifySmsVerificationCodeParam)) {
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_LOST, "入参缺失");
        }

        // 校验 award 是否为null
        if (Objects.isNull(verifySmsVerificationCodeParam.getAward())) {
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_LOST, "award不能为空");
        }

        // 验签
        Map<String, Object> map = JsonUtil.convertValueSnake(verifySmsVerificationCodeParam.getAward(), new TypeReference<Map<String, Object>>() {
        });
        String drawAwardKey = signConfig.getAwardKey();
        boolean awardSign = SignUtil.checkSign(map, drawAwardKey);
        if (!awardSign) {
            return XmResultJson.fail(ReqErrorCodeConstants.SIGN_ERROR, "invalid signature");
        }

        // 参数转换
        VerifySmsCodeParam verifySmsCodeParam = JSON.parseObject(JSON.toJSONString(verifySmsVerificationCodeParam.getAward()), VerifySmsCodeParam.class);
        verifySmsCodeParam.setCode(verifySmsVerificationCodeParam.getCode());
        verifySmsCodeParam.setPhone(verifySmsVerificationCodeParam.getPhone());

        // 校验 verifySmsCodeParam 参数
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(verifySmsCodeParam);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }

        ServiceResult result = awardDrawDisplayService.verifySmsAuthCode(verifySmsCodeParam);
        if (result.isSuccess()) {
            // 生成签名
            verifySmsVerificationCodeParam.getAward().remove("sig");
            verifySmsVerificationCodeParam.getAward().put("phone",verifySmsVerificationCodeParam.getPhone());
            map = JsonUtil.convertValueSnake(verifySmsVerificationCodeParam.getAward(), new TypeReference<Map<String, Object>>() {
            });
            String sig = SignUtil.genSign(map, drawAwardKey);
            verifySmsVerificationCodeParam.getAward().put("sig",sig);

            VerifySmsVerificationCodeOuterVO verifySmsVerificationCodeOuterVO
                    = DrawAwardConvert.verifySmsVerificationCodeParamToVO(verifySmsVerificationCodeParam);
            return XmResultJson.success(verifySmsVerificationCodeOuterVO);
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 获取中奖名单
     *
     * @param awardId   奖励id
     * @param request   token获取orgId
     * @param level     奖项等级
     * @param name      奖项名称
     * @param status    中奖状态
     * @param page      第几页
     * @param size      每一页条数
     * @param deliverId 投放id
     * @param recordId  中奖记录id
     * @param phone     手机号
     * @return 中奖名单
     */
    @ApiOperation(value = "获取中奖名单")
    @GetMapping(value = "draw/win")
    public XmResultJson<ListWinnersPageVO> listWinners(
            @RequestParam(value = "id") String awardId,
            @RequestParam(value = "level", defaultValue = "100") Integer level,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", defaultValue = "0") Integer status,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "size", defaultValue = "10") Integer size,
            @RequestParam(value = "deliver_id", required = false) String deliverId,
            @RequestParam(value = "record_id", required = false) String recordId,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "deliver_source", required = false) Integer deliverSource,
            HttpServletRequest request) {
        PageParam pageParam = new PageParam();
        pageParam.setSize(size);
        pageParam.setPage(page);

        // 参数校验 pageParam
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(pageParam);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }

        // token获取orgId
        
        String orgId = SecurityContextHolder.getOrgId();

        // controller 参数 转 service 参数
        GetWinnersParam getWinnersParam = new GetWinnersParam();
        getWinnersParam.setRecordId(recordId);
        getWinnersParam.setAwardId(awardId);
        getWinnersParam.setDeliverId(deliverId);
        getWinnersParam.setLevel(level);
        getWinnersParam.setName(name);
        getWinnersParam.setOrgId(orgId);
        getWinnersParam.setPhone(phone);
        getWinnersParam.setStatus(status);
        getWinnersParam.setPage(pageParam);
        getWinnersParam.setDeliverSource(deliverSource);

        // 参数校验 getWinnersParam
        violations = GRpcUtil.validateParam(getWinnersParam);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }

        ServiceResult<PageResultDTO<RecordDTO>> result = awardDrawDisplayService.listWinners(getWinnersParam);
        if (result.isSuccess()) {
            ListWinnersPageVO listWinnersPageVO = DrawAwardConvert.listWinnersConversion(result.getData());
            return XmResultJson.success(listWinnersPageVO);
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }


    /**
     * 获取中奖名单中的奖项信息
     *
     * @param awardId   奖励id
     * @param request   token获取orgId
     * @param recordId  中奖记录id
     * @param deliverId 投放id
     * @param level     奖项等级
     * @param name      奖项名称
     * @param status    中奖状态
     * @param page      第几页
     * @param size      每一页条数
     * @return 中奖名单中的奖项信息
     */
    @ApiOperation(value = "获取中奖名单中的奖项信息")
    @GetMapping(value = "draw/win/award")
    public XmResultJson<ListWinnerDetailsPageVO> listWinnerDetails(
            @RequestParam(value = "id") String awardId,
            @RequestParam(value = "record_id",required = false) String recordId,
            @RequestParam(value = "deliver_id",required = false) String deliverId,
            @RequestParam(value = "level", defaultValue = "100") Integer level,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "status", defaultValue = "100") Integer status,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "size", defaultValue = "10") Integer size,
            HttpServletRequest request) {
        // token获取orgId
        
        String orgId = SecurityContextHolder.getOrgId();

        // 参数包装成对象
        ListWinnerDetailsReceiveParam listWinnerDetailsReceiveParam = new ListWinnerDetailsReceiveParam();
        listWinnerDetailsReceiveParam.setAwardId(awardId);
        listWinnerDetailsReceiveParam.setDeliverId(deliverId);
        listWinnerDetailsReceiveParam.setLevel(level);
        listWinnerDetailsReceiveParam.setName(name);
        listWinnerDetailsReceiveParam.setOrgId(orgId);
        listWinnerDetailsReceiveParam.setPage(page);
        listWinnerDetailsReceiveParam.setSize(size);
        listWinnerDetailsReceiveParam.setStatus(status);
        listWinnerDetailsReceiveParam.setRecordId(recordId);

        // 参数校验
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(listWinnerDetailsReceiveParam);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }

        // controller 参数 转 service 参数
        ListWinnerDetailsParam listWinnerDetailsParam = new ListWinnerDetailsParam();
        listWinnerDetailsParam.setRecordId(listWinnerDetailsReceiveParam.getRecordId());
        listWinnerDetailsParam.setAwardId(listWinnerDetailsReceiveParam.getAwardId());
        listWinnerDetailsParam.setDeliverId(listWinnerDetailsReceiveParam.getDeliverId());
        listWinnerDetailsParam.setLevel(listWinnerDetailsReceiveParam.getLevel());
        listWinnerDetailsParam.setName(listWinnerDetailsReceiveParam.getName());
        listWinnerDetailsParam.setOrgId(listWinnerDetailsReceiveParam.getOrgId());
        listWinnerDetailsParam.setStatus(listWinnerDetailsReceiveParam.getStatus());
        PageParam pageParam = new PageParam();
        pageParam.setPage(listWinnerDetailsReceiveParam.getPage());
        pageParam.setSize(listWinnerDetailsReceiveParam.getSize());
        listWinnerDetailsParam.setPage(pageParam);

        ServiceResult<PageResultDTO<RecordDetailDTO>> result = awardDrawDisplayService.listWinnerDetails(listWinnerDetailsParam);
        if (result.isSuccess()) {
            ListWinnerDetailsPageVO listWinnerDetailsPageVO = DrawAwardConvert.listWinnerDetailsConversion(result.getData());
            return XmResultJson.success(listWinnerDetailsPageVO);
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 导出中奖名单
     *
     * @param exportWinnersParam award_id 奖励id，org_id 公司id，deliver_id 投放id
     * @param request            token获取orgId
     * @return 中奖名单url等信息
     */
    @ApiOperation("导出中奖名单")
    @PostMapping("draw/win/export")
    public XmResultJson<ExportWinnerOuterVO> exportWinner(@RequestBody ExportWinnersParam exportWinnersParam, HttpServletRequest request) {
        // token获取orgId
        
        String orgId = SecurityContextHolder.getOrgId();
        // 校验 exportWinnersParam 是否为null
        if (Objects.isNull(exportWinnersParam)) {
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_LOST, "入参缺失");
        }
        exportWinnersParam.setOrgId(orgId);

        // 参数校验
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(exportWinnersParam);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }

        ServiceResult<FileInfoDTO> result = awardDrawDisplayService.exportWinners(exportWinnersParam);
        if (result.isSuccess()) {
            ExportWinnerOuterVO exportWinnerOuterVO = DrawAwardConvert.exportWinnerConversion(result.getData());
            return XmResultJson.success(exportWinnerOuterVO);
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }


    /**
     * 导出中奖名单中的奖项信息
     *
     * @param expWinnerDetailsParam 导出中奖名单中的奖项信息请求参数
     * @param request HttpServletRequest
     * @return ExportWinnerDetailsVO
     */
    @ApiOperation("导出中奖名单中的奖项信息")
    @PostMapping("draw/win/award/export")
    public XmResultJson<ExportWinnerDetailsVO> exportWinnerDetails(@RequestBody ExpWinnerDetailsParam expWinnerDetailsParam,
            HttpServletRequest request) {
        // token获取orgId
        
        String orgId = SecurityContextHolder.getOrgId();
        ExportWinnerDetailsParam param = new ExportWinnerDetailsParam();
        param.setOrgId(orgId);
        param.setAwardId(expWinnerDetailsParam.getAwardId());
        param.setDeliverId(expWinnerDetailsParam.getDeliverId());
        param.setStatus(Objects.isNull(expWinnerDetailsParam.getStatus()) ? AwardIssueStatusEnum.ALL.getIndex() : expWinnerDetailsParam.getStatus());
        param.setName(expWinnerDetailsParam.getName());
        param.setLevel(Objects.isNull(expWinnerDetailsParam.getLevel()) ? AwardLevelEnum.LEVEL_ALL.getIndex() : expWinnerDetailsParam.getLevel());
        // 参数转换校验
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(param);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(ReqErrorCodeConstants.PARAM_FORMAT, violation.getMessage());
        }
        ServiceResult<FileInfoDTO> result = awardDrawDisplayService.exportWinnerDetails(param);
        if (result.isSuccess()) {
            ExportWinnerDetailsVO exportWinnerDetailsVO = new ExportWinnerDetailsVO();
            exportWinnerDetailsVO.setFileInfo(result.getData());
            return XmResultJson.success(exportWinnerDetailsVO);
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 抽奖
     *
     * @param requestParam  抽奖请求参数
     * @param bindingResult 参数校验
     * @return 抽奖结果
     */
    @PostMapping(value = "/draw")
    public XmResultJson<DrawAwardVO> drawAward(@RequestBody @Validated DrawAwardRequestParam requestParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return XmResultJson.fail(1, bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        // 验签
        String drawAwardKey = signConfig.getAwardKey();
        boolean respondentSign = SignUtil.checkSign(requestParam.getAward(), drawAwardKey);
        if (!respondentSign) {
            return XmResultJson.fail(ReqErrorCodeConstants.SIGN_ERROR, "invalid signature");
        }
        // 参数转换校验
        DrawAwardParam param = requestParam.getDrawAwardParam();
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(param);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(1, violation.getMessage());
        }
        ServiceResult<DrawAwardResultDTO> result = awardDrawDisplayService.drawAward(param);
        if (result.isSuccess()) {
            DrawAwardResultDTO dto = result.getData();
            DrawAwardVO vo = new DrawAwardVO();
            BeanUtils.copyProperties(dto, vo);
            return XmResultJson.success(vo);
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 保存中奖信息
     *
     * @param requestParam  保存中奖信息请求参数
     * @param bindingResult 参数校验
     * @return 保存结果
     */
    @PutMapping(value = "/draw")
    public XmResultJson saveWinnerMessage(@RequestBody @Validated SaveWinnerMessageRequestParam requestParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return XmResultJson.fail(1, bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        // 验签
        String drawAwardKey = signConfig.getAwardKey();
        boolean respondentSign = SignUtil.checkSign(requestParam.getAward(), drawAwardKey);
        if (!respondentSign) {
            return XmResultJson.fail(ReqErrorCodeConstants.SIGN_ERROR, "invalid signature");
        }
        // 参数转换校验
        SaveWinnerMessageParam param = requestParam.getSaveWinnerMessageParam();
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(param);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(1, violation.getMessage());
        }
        ServiceResult<Long> result = awardDrawDisplayService.saveWinnerMessage(param);
        if (result.isSuccess()) {
            return XmResultJson.success();
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 获取抽奖详情
     *
     * @param id 奖励id
     * @param deliverId 投放id
     * @param request HttpServletRequest
     * @return 抽奖详情信息
     */
    @GetMapping(value = "/draw/win/num")
    public XmResultJson<GetAwardDetailDTO> getAwardDetail(@RequestParam(value = "id") String id,
                                                          @RequestParam(value = "deliver_id", required = false) String deliverId,
                                                          HttpServletRequest request) {

        
        String orgId = SecurityContextHolder.getOrgId();
        GetAwardDetailParam param = new GetAwardDetailParam(id, orgId, deliverId);
        Set<ConstraintViolation<Object>> violations = GRpcUtil.validateParam(param);
        if (!CollectionUtils.isEmpty(violations)) {
            ConstraintViolation<Object> violation = violations.iterator().next();
            return XmResultJson.fail(1, violation.getMessage());
        }
        ServiceResult<GetAwardDetailDTO> result = awardDrawDisplayService.getAwardDetail(param);
        if (result.isSuccess()) {
            return XmResultJson.success(result.getData());
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 修改中奖状态
     *
     * @param requestParam  修改中奖状态请求参数
     * @param bindingResult 参数校验
     * @return 修改结果(条数)
     */
    @PutMapping(value = "/draw/win/status")
    public XmResultJson<UpdateWinnerStatusVO> updateWinnerStatus(@RequestBody @Validated UpdateStatusRequestParam requestParam, BindingResult bindingResult,
                                                                 HttpServletRequest request) {
        if (bindingResult.hasErrors()) {
            return XmResultJson.fail(1, bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        
        String orgId = SecurityContextHolder.getOrgId();
        UpdateStatusParam param = new UpdateStatusParam();
        BeanUtils.copyProperties(requestParam, param);
        param.setOrgId(orgId);
        ServiceResult<Long> result = awardDrawDisplayService.updateWinnerStatus(param);
        if (result.isSuccess()) {
            return XmResultJson.success(new UpdateWinnerStatusVO(result.getData()));
        } else {
            return XmResultJson.fail(1, result.getMsg());
        }
    }

    /**
     * 创建抽奖奖励
     *
     * @param param         创建奖励请求参数
     * @param bindingResult 参数校验
     * @return {@link CreateAwardVO}
     */
    @PostMapping("/award/draw")
    public XmResultJson<CreateAwardVO> createDrawAward(@RequestBody @Validated CreateDrawAwardParam param, BindingResult bindingResult,
                                                       HttpServletRequest request) {
        if (bindingResult.hasErrors()) {
            return XmResultJson.fail(1, bindingResult.getAllErrors().get(0).getDefaultMessage());
        }

        AwardAwardBO awardAward = DrawAwardConvert.drawAwardDtoToAward(param.getAward());
        WinDataBO winData = WinDataConvert.windataDTOToWinDataBO(param.getWinData());
        
        String orgId = SecurityContextHolder.getOrgId();
        awardAward.setOrgId(orgId);
        CreateAwardDTO serviceParam = new CreateAwardDTO();
        serviceParam.setAwardAward(awardAward);
        serviceParam.setWinData(winData);
        ServiceResult<String> serviceResult = awardDispatcher.createAward(serviceParam);
        if (serviceResult.isSuccess()) {
            CreateAwardVO createAwardVO = new CreateAwardVO();
            createAwardVO.setId(serviceResult.getData());
            return XmResultJson.success(createAwardVO);
        } else {
            return XmResultJson.fail(serviceResult.getErrorData(), serviceResult.getMsg());
        }
    }
}